const { sequelize } = require("../../core/db");
const { Sequelize, Model } = require("sequelize");
class News extends Model {}

News.init(
  {
    news_id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    title: {
      type: Sequelize.STRING,
      allowNull: false,
    },
    image: Sequelize.STRING,
    fav_num: {
      type: Sequelize.INTEGER, //点赞数
      allowNull: false,
      defaultValue: 0,
    },
    is_del: {
      type: Sequelize.INTEGER,
      defaultValue: 0,
    },
    admin_id: {
      type: Sequelize.INTEGER,
      defaultValue: 1,
      comment: "创建文章的管理员id",
    },
    content: {
      type: Sequelize.TEXT("long"),
    },
    digest: {
      type: Sequelize.STRING,
      comment: "图文消息的摘要，仅有单图文消息才有摘要，多图文此处为空",
    },
    url: {
      type: Sequelize.STRING,
      comment: "图文消息的URL",
    },
    author: {
      type: Sequelize.STRING,
      comment: "作者",
    },
  },
  {
    sequelize,
    tableName: "news",
  }
);




//  News.addHook("beforeCreate", async (news, options) => {
//    // 删除缓存
//    console.log(12345678901234567890);
//    await redis.del(`news:${news.news_id}`);
//  });

module.exports = {
  News,
};
